// stores/userStore.js
import { defineStore } from 'pinia'

export const useUserStore = defineStore('user', {
  state: () => ({
    id: null,
    name: null,
    avatar: null,
    role: null,
    isLoggedIn: false
  }),
  getters: {
    isAdmin: (state) => state.role === 'admin',
    isStaff: (state) => state.role === 'staff'
  },
  actions: {
    setUser(userData) {
      this.id=userData.user_id
      this.name = userData.username
      this.avatar = userData.avatar
      this.role = userData.role
      this.isLoggedIn = true
    },
    logout() {
      this.name = null
      this.avatar = null
      this.role = null
      this.isLoggedIn = false
    }
  },
  persist: true 
})